##
## Create: 2015-08-04-07-16
## Author: jmdvirus@roamter.com
## 

infile=$1
if [ "$infile" == "" ]; then
    infile=kfconfig.bin
fi

pass=r3ra21a8?321:1adf,2a

outpos=$2
if [ "$outpos" == "" ]; then
    outpos=.
fi 

if [ ! -f $infile ]; then
    echo "[ $infile ] not exist, please check !"
    exit -1
fi

CRYPTO=openssl
#CRYPTO=polarssl

if [ "$CRYPTO" == "openssl" ]; then
    dd if=$infile | openssl des3 -d -k $pass | tar zxf - -C $outpos
elif [ "$CRYPTO" == "polarssl" ] ; then
    polarssl_aescrypt2 1 $infile $infile.tmp string:$pass
    tar zxf $infile.tmp
    rm $infile.tmp
fi

if [ "$?" == "0" ]; then
    echo "Decompress [ $infile ] success."
fi
